package org.jsemantic.support.examples.mvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jsemantic.servicerules.examples.energy.EnergyInvoiceApp;
import org.jsemantic.servicerules.examples.energy.model.Invoice;
import org.jsemantic.servicerules.examples.energy.services.InvoiceService;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class InvoiceController extends AbstractController {

	private InvoiceService invoiceService = null;

	public void setInvoiceService(InvoiceService invoiceService) {
		this.invoiceService = invoiceService;
	}

	protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		Invoice invoice = invoiceService.createInvoice(
				EnergyInvoiceApp.generator.getCustomer(),
				EnergyInvoiceApp.generator.getMeterReading());

		ModelAndView mv = new ModelAndView("invoiceView");
		mv.addObject(invoice);	
		return mv;
	}

}
